package com.ruihang.ijkplaylib.widget;

import android.app.Activity;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.media.AudioManager;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.provider.Settings;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.OrientationEventListener;
import android.view.Surface;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;

import com.ruihang.ijkplaylib.R;
import com.ruihang.ijkplaylib.bean.IPlayClarity;
import com.ruihang.ijkplaylib.bean.VideoijkBean;
import com.ruihang.ijkplaylib.listener.OnStatusChanged;
import com.ruihang.ijkplaylib.utils.NetworkUtils;
import com.ruihang.ijkplaylib.utils.PlayerUtils;

import java.util.ArrayList;
import java.util.List;

import tv.danmaku.ijk.media.player.IMediaPlayer;
import tv.danmaku.ijk.media.player.IjkMediaPlayer;

/**
 * Created by liuyu on 2017/7/20.
 *
 * @author liuyu
 */

public class EmptyPlayerView {

    /**
     * 同步进度
     */
    private static final int MESSAGE_SHOW_PROGRESS = 1;
    /**
     * 设置新位置
     */
    private static final int MESSAGE_SEEK_NEW_POSITION = 3;
    /**
     * 隐藏提示的box
     */
    private static final int MESSAGE_HIDE_CENTER_BOX = 4;
    /**
     * 重新播放
     */
    private static final int MESSAGE_RESTART_PLAY = 5;


    /**
     * 打印日志的TAG
     */
    private static final String TAG = EmptyPlayerView.class.getSimpleName();

    private Context context;
//    private Activity mActivity;
//    /**
//     * 最底层的布局
//     */
//    private final ViewGroup baseLay;
    /**
     * 原生的Ijkplayer
     */
    private final IjkVideoView videoView;
    /**
     //     * 菜单面板
     //     */
//    private final View settingsContainer;
    /**
     * 中部整个播放屏幕的显示控制
     */
    private IGPlayerScreenControll screenControll;
    /**
     * 顶部的显示控制
     */
    private IGPlayerTopControll topControll;
    /**
     * 底部的显示控制
     */
    private IGPlayerBottomControll bottomControll;
    /**
     * 声音亮度控制
     */
    private IGPlayerVoBrControll voBrControll;
    /**
     * 当前状态
     */
    private int status = PlayStateParams.STATE_IDLE;
    /**
     * 当前播放位置
     */
    private int currentPosition;
    /**
     * 滑动进度条得到的新位置，和当前播放位置是有区别的,newPosition =0也会调用设置的，故初始化值为-1
     */
    private long newPosition = -1;
    /**
     * 视频旋转的角度，默认只有0,90.270分别对应向上、向左、向右三个方向
     */
    private int rotation = 0;
    /**
     * 视频显示比例,默认保持原视频的大小
     */
    private int currentShowType = PlayStateParams.fitparent;
    /**
     * 播放总时长
     */
    private long duration;
    /**
     * 当前声音大小
     */
    private int volume;
    /**
     * 设备最大音量
     */
    private final int mMaxVolume;
//    /**
//     * 获取当前设备的宽度
//     */
//    private final int screenWidthPixels;
    /**
     //     * 记录播放器竖屏时的高度
     //     */
//    private final int initHeight;
    /**
     * 当前亮度大小
     */
    private float brightness;
    /**
     * 当前播放地址
     */
    private String currentUrl;
    /**
     * 当前播放清晰度
     */
    private IPlayClarity currentCalarity;
    /**
     * 当前选择的视频流索引
     */
    private int currentSelect;
    /**
     * 码流列表
     */
    private List<IPlayClarity> listVideos = new ArrayList<IPlayClarity>();
    /**
     * 自动重连的时间
     */
    private int autoConnectTime = 2000;
    /**
     * 第三方so是否支持，默认不支持，true为支持
     */
    private boolean playerSupport;
    /**
     * 是否是直播 默认为非直播，true为直播false为点播，根据isLive()方法前缀rtmp判断得出的为直播，比较片面
     * ，可手动设置，有好的建议欢迎交流
     */
    private boolean isLive;
    /**
     * 是否显示控制面板，默认为隐藏，true为显示false为隐藏
     */
    private boolean isShowControlPanl;
    /**
     * 禁止触摸，默认可以触摸，true为禁止false为可触摸
     */
    private boolean isForbidTouch;
    /**
     * 当前是否切换视频流，默认为否，true是切换视频流，false没有切换
     */
    private boolean isHasSwitchStream;
    /**
     * 是否在拖动进度条中，默认为停止拖动，true为在拖动中，false为停止拖动
     */
    private boolean isDragging;
    /**
     * 播放的时候是否需要网络提示，默认显示网络提示，true为显示网络提示，false不显示网络提示
     */
    private boolean isGNetWork = true;
    /**
     * 是否禁止双击，默认不禁止，true为禁止，false为不禁止
     */
    private boolean isForbidDoulbeUp;
    /**
     * 是否是竖屏，默认为竖屏，true为竖屏，false为横屏
     */
    private boolean isPortrait = true;
    /**
     * 是否出错停止播放，默认是出错停止播放，true出错停止播放,false为用户点击停止播放
     */
    private boolean isErrorStop = true;
    /**
     * 是否自动重连，默认5秒重连，true为重连，false为不重连
     */
    private boolean isAutoReConnect = true;
    /**
     * 音频管理器
     */
    private final AudioManager audioManager;

    private IMediaPlayer.OnSeekCompleteListener seekCompleteListener;
    /**
     * 是否自动隐藏控制条等
     */
    private boolean isAutoPlay;

    /**
     * 视频播放时信息回调
     */
    private IMediaPlayer.OnInfoListener onInfoListener;
    /**
     * 状态改变监控接口
     */
    private OnStatusChanged onStatusChanged;
//    /**
//     * Activity界面方向监听
//     */
//    private final OrientationEventListener orientationEventListener;

    private IMediaPlayer.OnSeekCompleteListener defSeekCompleteListener = new IMediaPlayer.OnSeekCompleteListener() {
        @Override
        public void onSeekComplete(IMediaPlayer iMediaPlayer) {
            if (seekCompleteListener != null) {
                seekCompleteListener.onSeekComplete(iMediaPlayer);
            }
        }
    };

    /**
     * 消息处理
     */
    @SuppressWarnings("HandlerLeak")
    private Handler mHandler = new Handler(Looper.getMainLooper()) {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
        }
    };

    /**
     * 控制面板收起或者显示的轮询监听
     */
    private AutoPlayRunnable mAutoPlayRunnable = new AutoPlayRunnable();


    /**
     * 新的调用方法，适用非Activity中使用GPlayerView，例如fragment、holder中使用
     */
    public EmptyPlayerView(Context context, IjkVideoView videoView) {
        this.context = context;
        try {
            IjkMediaPlayer.loadLibrariesOnce(null);
            IjkMediaPlayer.native_profileBegin("libijkplayer.so");
            playerSupport = true;
        } catch (Throwable e) {
            Log.e(TAG, "loadLibraries error", e);
        }
//        screenWidthPixels = mActivity.getResources().getDisplayMetrics().widthPixels;
        audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        mMaxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
        this.videoView = videoView;

        videoView.setMute(true);
//        LayoutInflater inflater = LayoutInflater.from(mActivity);
//        if (screenControll != null) {
//            screenControll.onAddingView(this, inflater, baseLay);
//        }
//        if (topControll != null) {
//            topControll.onAddingView(this, inflater, baseLay);
//        }
//        if (bottomControll != null) {
//            bottomControll.onAddingView(this, inflater, baseLay);
//        }
//        if (voBrControll != null) {
//            voBrControll.onAddingView(this, inflater, baseLay);
//        }

        try {
            int e = Settings.System.getInt(this.context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS);
            float progress = 1.0F * (float) e / 255.0F;
//            WindowManager.LayoutParams layout = this.context.getWindow().getAttributes();
//            layout.screenBrightness = progress;
//            mActivity.getWindow().setAttributes(layout);
        } catch (Settings.SettingNotFoundException var7) {
            var7.printStackTrace();
        }
//        brightnessController.setOnSeekBarChangeListener(this.onBrightnessControllerChangeListener);
//        if (rootView == null) {
//            streamSelectView = (LinearLayout) mActivity.findViewById(ResourceUtils.getResourceIdByName(mContext, "id", "simple_player_select_stream_container"));
//            streamSelectListView = (ListView) mActivity.findViewById(ResourceUtils.getResourceIdByName(mContext, "id", "simple_player_select_streams_list"));
//            ll_topbar = mActivity.findViewById(ResourceUtils.getResourceIdByName(mContext, "id", "app_video_top_box"));
//            ll_bottombar = mActivity.findViewById(ResourceUtils.getResourceIdByName(mContext, "id", "ll_bottom_bar"));
//            iv_trumb = (ImageView) mActivity.findViewById(ResourceUtils.getResourceIdByName(mContext, "id", "iv_trumb"));
//            iv_back = (ImageView) mActivity.findViewById(ResourceUtils.getResourceIdByName(mContext, "id", "app_video_finish"));
//            iv_menu = (ImageView) mActivity.findViewById(ResourceUtils.getResourceIdByName(mContext, "id", "app_video_menu"));
//            iv_bar_player = (ImageView) mActivity.findViewById(ResourceUtils.getResourceIdByName(mContext, "id", "app_video_play"));
//            iv_player = (ImageView) mActivity.findViewById(ResourceUtils.getResourceIdByName(mContext, "id", "play_icon"));
//            iv_rotation = (ImageView) mActivity.findViewById(ResourceUtils.getResourceIdByName(mContext, "id", "ijk_iv_rotation"));
//            iv_fullscreen = (ImageView) mActivity.findViewById(ResourceUtils.getResourceIdByName(mContext, "id", "app_video_fullscreen"));
//            tv_steam = (TextView) mActivity.findViewById(ResourceUtils.getResourceIdByName(mContext, "id", "app_video_stream"));
//            tv_speed = (TextView) mActivity.findViewById(ResourceUtils.getResourceIdByName(mContext, "id", "app_video_speed"));
//            seekBar = (SeekBar) mActivity.findViewById(ResourceUtils.getResourceIdByName(mContext, "id", "app_video_seekBar"));
//        } else {
//            streamSelectView = (LinearLayout) rootView.findViewById(ResourceUtils.getResourceIdByName(mContext, "id", "simple_player_select_stream_container"));
//            streamSelectListView = (ListView) rootView.findViewById(ResourceUtils.getResourceIdByName(mContext, "id", "simple_player_select_streams_list"));
//            ll_topbar = rootView.findViewById(ResourceUtils.getResourceIdByName(mContext, "id", "app_video_top_box"));
//            ll_bottombar = rootView.findViewById(ResourceUtils.getResourceIdByName(mContext, "id", "ll_bottom_bar"));
//            iv_trumb = (ImageView) rootView.findViewById(ResourceUtils.getResourceIdByName(mContext, "id", "iv_trumb"));
//            iv_back = (ImageView) rootView.findViewById(ResourceUtils.getResourceIdByName(mContext, "id", "app_video_finish"));
//            iv_menu = (ImageView) rootView.findViewById(ResourceUtils.getResourceIdByName(mContext, "id", "app_video_menu"));
//            iv_bar_player = (ImageView) rootView.findViewById(ResourceUtils.getResourceIdByName(mContext, "id", "app_video_play"));
//            iv_player = (ImageView) rootView.findViewById(ResourceUtils.getResourceIdByName(mContext, "id", "play_icon"));
//            iv_rotation = (ImageView) rootView.findViewById(ResourceUtils.getResourceIdByName(mContext, "id", "ijk_iv_rotation"));
//            iv_fullscreen = (ImageView) rootView.findViewById(ResourceUtils.getResourceIdByName(mContext, "id", "app_video_fullscreen"));
//            tv_steam = (TextView) rootView.findViewById(ResourceUtils.getResourceIdByName(mContext, "id", "app_video_stream"));
//            tv_speed = (TextView) rootView.findViewById(ResourceUtils.getResourceIdByName(mContext, "id", "app_video_speed"));
//            seekBar = (SeekBar) rootView.findViewById(ResourceUtils.getResourceIdByName(mContext, "id", "app_video_seekBar"));
//        }

//        seekBar.setMax(1000);
//        seekBar.setOnSeekBarChangeListener(mSeekListener);
//        iv_bar_player.setOnClickListener(onClickListener);
//        iv_player.setOnClickListener(onClickListener);
//        iv_fullscreen.setOnClickListener(onClickListener);
//        iv_rotation.setOnClickListener(onClickListener);
//        tv_steam.setOnClickListener(onClickListener);
//        iv_back.setOnClickListener(onClickListener);
//        iv_menu.setOnClickListener(onClickListener);
//        query.id(ResourceUtils.getResourceIdByName(mContext, "id", "app_video_netTie_icon")).clicked(onClickListener);
//        query.id(ResourceUtils.getResourceIdByName(mContext, "id", "app_video_replay_icon")).clicked(onClickListener);
        videoView.setOnSeekCompleteListener(defSeekCompleteListener);
        videoView.setOnInfoListener(new IMediaPlayer.OnInfoListener() {
            @Override
            public boolean onInfo(IMediaPlayer mp, int what, int extra) {
                if (screenControll != null) {
                    screenControll.onInfo(mp, what, extra);
                }
                statusChange(what);
                if (onInfoListener != null) {
                    onInfoListener.onInfo(mp, what, extra);
                }
                return true;
            }
        });
        videoView.setOnCompletionListener(new IMediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(IMediaPlayer iMediaPlayer) {
                currentPosition = 0;
                statusChange(PlayStateParams.STATE_COMPLETED);
                if (onInfoListener != null) {
                    onInfoListener.onInfo(iMediaPlayer, PlayStateParams.STATE_COMPLETED, 0);
                }

            }
        });
//        this.streamSelectAdapter = new StreamSelectAdapter(mContext, listVideos);
//        this.streamSelectListView.setAdapter(this.streamSelectAdapter);
//        this.streamSelectListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                hideStreamSelectView();
//                if (currentSelect == position) {
//                    return;
//                }
//                currentSelect = position;
//                switchStream(position);
//                for (int i = 0; i < listVideos.size(); i++) {
//                    if (i == position) {
//                        listVideos.get(i).setSelect(true);
//                    } else {
//                        listVideos.get(i).setSelect(false);
//                    }
//                }
//                streamSelectAdapter.notifyDataSetChanged();
//                startPlay();
//            }
//        });

//        final GestureDetector gestureDetector = new GestureDetector(mActivity, new PlayerGestureListener());
//        baseLay.setClickable(true);
//        baseLay.setOnTouchListener(new View.OnTouchListener() {
//            @Override
//            public boolean onTouch(View view, MotionEvent motionEvent) {
//                switch (motionEvent.getAction() & MotionEvent.ACTION_MASK) {
//                    case MotionEvent.ACTION_DOWN:
//                        if (mAutoPlayRunnable != null) {
//                            mAutoPlayRunnable.stop();
//                        }
//                        break;
//                }
//                if (gestureDetector.onTouchEvent(motionEvent)) {
//                    if (isAutoPlay && mAutoPlayRunnable != null) {
//                        mAutoPlayRunnable.start();
//                    }
//                    return true;
//                }
//                // 处理手势结束
//                switch (motionEvent.getAction() & MotionEvent.ACTION_MASK) {
//                    case MotionEvent.ACTION_UP:
//                        endGesture();
//                        break;
//                }
//                return false;
//            }
//        });


//        orientationEventListener = new OrientationEventListener(mActivity) {
//            @Override
//            public void onOrientationChanged(int orientation) {
//                if (orientation >= 0 && orientation <= 30 || orientation >= 330 || (orientation >= 150 && orientation <= 210)) {
//                    //竖屏
//                    if (isPortrait) {
//                        mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
//                        orientationEventListener.disable();
//                    }
//                } else if ((orientation >= 90 && orientation <= 120) || (orientation >= 240 && orientation <= 300)) {
//                    if (!isPortrait) {
//                        mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
//                        orientationEventListener.disable();
//                    }
//                }
//            }
//        };
//        if (bottomControll != null && !bottomControll.canChangeScreen()) {
//            mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
//        }
        isPortrait = (getScreenOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
//        initHeight = baseLay.getLayoutParams().height;
        hideAll();
        if (!playerSupport) {
            showStatus(context.getString(R.string.not_support));
        } else {
//            query.id(ResourceUtils.getResourceIdByName(mContext, "id", "ll_bg")).visible();
            if (screenControll != null) {
                screenControll.onShowSome(IGPlayerScreenControll.MODE_BG);
            }
        }
    }

    /**
     * 获取界面方向
     */
    public int getScreenOrientation() {
//        int rotation = mActivity.getWindowManager().getDefaultDisplay().getRotation();
        DisplayMetrics dm = new DisplayMetrics();
//        mActivity.getWindowManager().getDefaultDisplay().getMetrics(dm);
        int width = dm.widthPixels;
        int height = dm.heightPixels;
        int orientation;
        // if the device's natural orientation is portrait:
        if ((rotation == Surface.ROTATION_0
                || rotation == Surface.ROTATION_180) && height > width ||
                (rotation == Surface.ROTATION_90
                        || rotation == Surface.ROTATION_270) && width > height) {
            switch (rotation) {
                case Surface.ROTATION_0:
                    orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
                    break;
                case Surface.ROTATION_90:
                    orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
                    break;
                case Surface.ROTATION_180:
                    orientation =
                            ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
                    break;
                case Surface.ROTATION_270:
                    orientation =
                            ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
                    break;
                default:
                    orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
                    break;
            }
        }
        // if the device's natural orientation is landscape or if the device
        // is square:
        else {
            switch (rotation) {
                case Surface.ROTATION_0:
                    orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
                    break;
                case Surface.ROTATION_90:
                    orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
                    break;
                case Surface.ROTATION_180:
                    orientation =
                            ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
                    break;
                case Surface.ROTATION_270:
                    orientation =
                            ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
                    break;
                default:
                    orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
                    break;
            }
        }

        return orientation;
    }

    /**
     * 设置播放地址
     * 包括视频清晰度列表
     * 对应地址列表
     */
    public EmptyPlayerView setPlaySource(List<? extends IPlayClarity> list) {
        listVideos.clear();
//        setPlayEnable(true);
        if (list != null && list.size() > 0) {
            listVideos.addAll(list);
            switchStream(0);
        }
        return this;
    }

    /**
     * 设置播放地址
     * 包括视频清晰度列表
     * 对应地址列表
     */
    public EmptyPlayerView setPlaySource(List<? extends IPlayClarity> list, int defPos) {
        listVideos.clear();
//        setPlayEnable(true);
        if (list != null && list.size() > 0) {
            listVideos.addAll(list);
            if (defPos < 0 || defPos >= list.size()) {
                defPos = 0;
            }
            switchStream(defPos);
        }
        return this;
    }

    /**
     * 设置播放地址
     * 单个视频VideoijkBean
     */
    public EmptyPlayerView setPlaySource(IPlayClarity videoijkBean) {
        listVideos.clear();
//        setPlayEnable(true);
        if (videoijkBean != null) {
            listVideos.add(videoijkBean);
            switchStream(0);
        }
        return this;
    }

    /**
     * 设置播放地址
     * 单个视频地址时
     * 带流名称
     */
    public EmptyPlayerView setPlaySource(String stream, String url) {
        VideoijkBean mVideoijkBean = new VideoijkBean();
        mVideoijkBean.setStream(stream);
        mVideoijkBean.setUrl(url);
        setPlaySource(mVideoijkBean);
        return this;
    }

    /**
     * 设置播放地址
     * 单个视频地址时
     */
    public EmptyPlayerView setPlaySource(String url) {
        setPlaySource("标清", url);
        return this;
    }

    /**
     * 选择要播放的流
     */
    public EmptyPlayerView switchStream(int index) {
        Log.e(TAG, "index:" + index);
        if (listVideos.size() > index) {
//            tv_steam.setText(listVideos.get(index).getStream());
            currentCalarity = listVideos.get(index);
//            if (topControll!=null){
//                topControll.onClarityChange(currentCalarity);
//            }
            if (!TextUtils.isEmpty(currentCalarity.getUrl())) {
                if (currentUrl != null && !TextUtils.equals(currentUrl, currentCalarity.getUrl())) {
                    currentPosition = 0;
                }
                currentUrl = currentCalarity.getUrl();
            }

            listVideos.get(index).setSelect(true);
            isLive();
            if (videoView.isPlaying()) {
                getCurrentPosition();
                videoView.release(false);
//                videoView.release(false);
            }
//            hasOnPaused = false;
            isHasSwitchStream = true;
//            if (clarityChanged != null) {
//                clarityChanged.onClarityChanged(index);
//            }
        }
        return this;
    }

    /**
     * 设置是否使用自动隐藏播放条的功能
     */
    public EmptyPlayerView setAutoPlay(boolean autoPlay) {
        boolean b = isAutoPlay != autoPlay;
        isAutoPlay = autoPlay;
        if (b && videoView.isPlaying()) {
            if (isAutoPlay) {
                startAutoPlay();
            } else {
                stopAutoPlay();
            }
        }
        return this;
    }

    /**
     * 开始播放
     */
    public EmptyPlayerView startPlay() {
        if (isLive) {
            videoView.setVideoPath(currentUrl);
            videoView.seekTo(0);
        } else {
            if (isHasSwitchStream || status == PlayStateParams.STATE_ERROR) {
                //换源之后声音可播，画面卡住，主要是渲染问题，目前只是提供了软解方式，后期提供设置方式
                videoView.setRender(videoView.RENDER_TEXTURE_VIEW);
                videoView.setVideoPath(currentUrl);
                videoView.seekTo(currentPosition);
                isHasSwitchStream = false;
            }
        }
//        hideStatusUI();
//        if (isGNetWork && (NetworkUtils.getNetworkType(mActivity) == 4 || NetworkUtils.getNetworkType(mActivity) == 5 || NetworkUtils.getNetworkType(mActivity) == 6)) {
////            query.id(ResourceUtils.getResourceIdByName(mContext, "id", "app_video_netTie")).visible();
//            if (screenControll!=null){
//                screenControll.onShowSome(IGPlayerScreenControll.MODE_NET);
//            }
//        } else {
//            if (playerSupport) {
////                query.id(ResourceUtils.getResourceIdByName(mContext, "id", "app_video_loading")).visible();
//                if (screenControll!=null){
//                    screenControll.onProgressChanged(true);
//                }
//                videoView.start();
//            } else {
//                showStatus(mActivity.getString(R.string.not_support));
//            }
//        }
//        if(isAutoPlay && mAutoPlayRunnable!=null){
//            mAutoPlayRunnable.stop();
//            mAutoPlayRunnable.start();
//        }
        return this;
    }

    private void stopAutoPlay() {
        if (mAutoPlayRunnable != null) {
            mAutoPlayRunnable.stop();
        }
    }

    private void startAutoPlay() {
        if (isAutoPlay && mAutoPlayRunnable != null) {
            mAutoPlayRunnable.stop();
            mAutoPlayRunnable.start();
        }
    }

    /**
     * 暂停播放
     */
    public EmptyPlayerView pausePlay() {
        status = PlayStateParams.STATE_PAUSED;
        getCurrentPosition();
        videoView.pause();
        stopAutoPlay();
        return this;
    }

    /**
     * 停止播放
     */
    public EmptyPlayerView stopPlay() {
        videoView.stopPlayback();
        isErrorStop = true;
        if (mHandler != null) {
            mHandler.removeMessages(MESSAGE_RESTART_PLAY);
        }
        stopAutoPlay();
        return this;
    }

    /**
     * 设置播放位置
     */
    public EmptyPlayerView seekTo(int playtime) {
        videoView.seekTo(playtime);
        return this;
    }

    /**
     * 获取当前播放位置
     */
    public int getCurrentPosition() {
        if (!isLive) {
            currentPosition = videoView.getCurrentPosition();
        } else {
            /**直播*/
            currentPosition = -1;
        }
        return currentPosition;
    }

    /**
     * 获取视频播放总时长
     */
    public long getDuration() {
        duration = videoView.getDuration();
        return duration;
    }

    /**
     * 设置2/3/4/5G和WiFi网络类型提示，
     *
     * @param isGNetWork true为进行2/3/4/5G网络类型提示
     *                   false 不进行网络类型提示
     */
    public EmptyPlayerView setNetWorkTypeTie(boolean isGNetWork) {
        this.isGNetWork = isGNetWork;
        return this;
    }

    /**
     * 设置是否禁止双击
     */
    public EmptyPlayerView setForbidDoulbeUp(boolean flag) {
        this.isForbidDoulbeUp = flag;
        return this;
    }

    public int getStatus() {
        return status;
    }

    /**
     * 当前播放的是否是直播
     */
    public boolean isLive() {
        return isLive;
    }

    /**
     * 是否禁止触摸
     */
    public EmptyPlayerView forbidTouch(boolean forbidTouch) {
        this.isForbidTouch = forbidTouch;
        return this;
    }

    /**
     * 隐藏所有状态界面
     */
    public EmptyPlayerView hideAllUI() {
//        if (query != null) {
        hideAll();
//        }
        return this;
    }

    /**
     * 手势结束
     */
    private void endGesture() {
        volume = -1;
        brightness = -1f;
        if (newPosition >= 0) {
            mHandler.removeMessages(MESSAGE_SEEK_NEW_POSITION);
            mHandler.sendEmptyMessage(MESSAGE_SEEK_NEW_POSITION);
        } else {
            /**什么都不做(do nothing)*/
        }
        mHandler.removeMessages(MESSAGE_HIDE_CENTER_BOX);
        mHandler.sendEmptyMessageDelayed(MESSAGE_HIDE_CENTER_BOX, 500);
        if (isAutoPlay && mAutoPlayRunnable != null) {
            mAutoPlayRunnable.start();
        }

    }

    private void setPlayStatus(int newStatus) {
        boolean hasChanged = this.status != newStatus;
        status = newStatus;
        if (hasChanged && onStatusChanged != null) {
            onStatusChanged.onStatusChanged(newStatus);
        }
    }

    /**
     * 状态改变同步UI
     */
    private void statusChange(int newStatus) {
        if (newStatus == PlayStateParams.STATE_COMPLETED) {
            setPlayStatus(PlayStateParams.STATE_COMPLETED);
            currentPosition = 0;
            hideAll();
            showStatus("播放结束");
        } else if (newStatus == PlayStateParams.STATE_PREPARING
                || newStatus == PlayStateParams.MEDIA_INFO_BUFFERING_START) {
            setPlayStatus(PlayStateParams.STATE_PREPARING);
            /**视频缓冲*/
            hideStatusUI();
            if (screenControll != null) {
                screenControll.onProgressChanged(true);
            }
        } else if (newStatus == PlayStateParams.MEDIA_INFO_VIDEO_RENDERING_START
                || newStatus == PlayStateParams.STATE_PLAYING
                || newStatus == PlayStateParams.STATE_PREPARED
                || newStatus == PlayStateParams.MEDIA_INFO_BUFFERING_END
                || newStatus == PlayStateParams.STATE_PAUSED) {
            if (newStatus == PlayStateParams.STATE_PAUSED) {
                setPlayStatus(PlayStateParams.STATE_PAUSED);
            } else {
                setPlayStatus(PlayStateParams.STATE_PLAYING);
            }
            /**视频缓冲结束后隐藏缩列图*/
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    hideStatusUI();
                    /**显示控制bar*/
                    isShowControlPanl = false;
                    if (!isForbidTouch) {
                        operatorPanl();
                    }
                    startAutoPlay();
                    /**延迟0.5秒隐藏视频封面隐藏*/
//                    query.id(ResourceUtils.getResourceIdByName(mContext, "id", "ll_bg")).gone();
                }
            }, 500);
        } else if (newStatus == PlayStateParams.MEDIA_INFO_VIDEO_INTERRUPT) {
            /**直播停止推流*/
            setPlayStatus(PlayStateParams.STATE_ERROR);
            if (!(isGNetWork &&
                    (NetworkUtils.getNetworkType(context) == 4
                            || NetworkUtils.getNetworkType(context) == 5
                            || NetworkUtils.getNetworkType(context) == 6))) {
                hideAll();
                if (isLive) {
                    showStatus("获取不到直播源");
                } else {
                    showStatus(context.getString(R.string.small_problem));
                }
                /**5秒尝试重连*/
                if (!isErrorStop && isAutoReConnect) {
                    mHandler.sendEmptyMessageDelayed(MESSAGE_RESTART_PLAY, autoConnectTime);
                }
            } else {
//                query.id(ResourceUtils.getResourceIdByName(mContext, "id", "app_video_netTie")).visible();
                if (screenControll != null) {
                    screenControll.onShowSome(IGPlayerScreenControll.MODE_NET);
                }
            }

        } else if (newStatus == PlayStateParams.STATE_ERROR
                || newStatus == PlayStateParams.MEDIA_INFO_UNKNOWN
                || newStatus == PlayStateParams.MEDIA_ERROR_IO
                || newStatus == PlayStateParams.MEDIA_ERROR_MALFORMED
                || newStatus == PlayStateParams.MEDIA_ERROR_UNSUPPORTED
                || newStatus == PlayStateParams.MEDIA_ERROR_TIMED_OUT
                || newStatus == PlayStateParams.MEDIA_ERROR_SERVER_DIED) {
            setPlayStatus(PlayStateParams.STATE_ERROR);
            if (!(isGNetWork && (NetworkUtils.getNetworkType(context) == 4
                    || NetworkUtils.getNetworkType(context) == 5
                    || NetworkUtils.getNetworkType(context) == 6))) {
                hideStatusUI();
                if (isLive) {
                    showStatus(context.getString(R.string.small_problem));
                } else {
                    showStatus(context.getString(R.string.small_problem));
                }
                /**5秒尝试重连*/
                if (!isErrorStop && isAutoReConnect) {
                    mHandler.sendEmptyMessageDelayed(MESSAGE_RESTART_PLAY, autoConnectTime);
                }
            } else {
                if (screenControll != null) {
                    screenControll.onShowSome(IGPlayerScreenControll.MODE_NET);
                }
            }
        }
    }

    /**
     * @Override protected void onPause() {
     * super.onPause();
     * if (player != null) {
     * player.onPause();
     * }
     * }
     */
    public EmptyPlayerView onPause() {
//        bgState = (videoView.isPlaying() ? 0 : 1);
        Log.e(TAG, "willGetPos");
        getCurrentPosition();
//        if (isLive) {
//            videoView.stopPlayback();
//        } else {
//        }
        videoView.onPause();
//        hasOnPaused = true;
        stopAutoPlay();
        return this;
    }

    /**
     * @Override protected void onResume() {
     * super.onResume();
     * if (player != null) {
     * player.onResume();
     * }
     * }
     */
    public EmptyPlayerView onResume() {
        videoView.onResume();
        Log.e(TAG, "ondemand isLive=" + isLive + "  currentPos=" + currentPosition);
        if (isLive) {
            videoView.seekTo(0);
        } else {
//            if (hasOnPaused) {
//                videoView.setRender(videoView.RENDER_TEXTURE_VIEW);
//                videoView.release(true);
//                videoView.setVideoPath(currentUrl);
//                videoView.seekTo(currentPosition);
//            } else {
//                videoView.seekTo(currentPosition);
//            }
        }
//        startAutoPlay();
//        if (bgState == 0) {
//            if (isLive) {
//                startPlay();
//            }
//        } else {
//            pausePlay();
//        }
        return this;
    }

    /**
     * @Override protected void onDestroy() {
     * super.onDestroy();
     * if (player != null) {
     * player.onDestroy();
     * }
     * }
     */
    public EmptyPlayerView onDestroy() {
//        orientationEventListener.disable();
        mHandler.removeMessages(MESSAGE_RESTART_PLAY);
        mHandler.removeMessages(MESSAGE_SEEK_NEW_POSITION);
//        fullScreenListener = null;
//        mOnShowThumbnailListener = null;
        onInfoListener = null;
        context = null;
        videoView.stopPlayback();
        if (topControll != null) {
            topControll.onDestory();
        }
        if (bottomControll != null) {
            bottomControll.onDestory();
        }
        if (screenControll != null) {
            screenControll.onDestory();
        }
        return this;
    }

    /**
     * 显示视频播放状态提示
     */
    private void showStatus(String statusText) {
//        query.id(ResourceUtils.getResourceIdByName(mContext, "id", "app_video_replay")).visible();
//        query.id(ResourceUtils.getResourceIdByName(mContext, "id", "app_video_status_text")).text(statusText);
        if (screenControll != null) {
            screenControll.showStatus(statusText);
        }
    }

    /**
     * 界面方向改变是刷新界面
     */
    private void doOnConfigurationChanged(final boolean portrait) {
        if (videoView != null) {
            boolean canChange = bottomControll == null || bottomControll.canChangeScreen();
            if (canChange) {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        tryFullScreen(!portrait);
                        if (portrait) {
//                            PlayerUtils.setViewHeight(baseLay, initHeight);
                            onPortraitControll();
                        } else {
//                            int heightPixels = context.getResources().getDisplayMetrics().heightPixels;
//                            int widthPixels = context.getResources().getDisplayMetrics().widthPixels;
//                            PlayerUtils.setViewHeight(baseLay, Math.min(heightPixels, widthPixels));
                            onLandscapeControll();
                        }
//                        updateFullScreenButton();
                    }
                });
//                orientationEventListener.enable();
            }
        }
    }

    public void onPortraitControll() {
        if (topControll != null) {
            topControll.onPortrait();
        }
        if (bottomControll != null) {
            bottomControll.onPortrait();
        }
        if (screenControll != null) {
            screenControll.onPortrait();
        }
    }

    public void onLandscapeControll() {
        if (topControll != null) {
            topControll.onLandscape();
        }
        if (bottomControll != null) {
            bottomControll.onLandscape();
        }
        if (screenControll != null) {
            screenControll.onLandscape();
        }
    }

    public EmptyPlayerView setSeekCompleteListener(IMediaPlayer.OnSeekCompleteListener seekCompleteListener) {
        this.seekCompleteListener = seekCompleteListener;
        return this;
    }


    /**
     * 设置界面方向
     */
    private void setFullScreen(boolean fullScreen) {
        if (context != null) {

//            WindowManager.LayoutParams attrs = context.getWindow().getAttributes();
//            if (fullScreen) {
//                attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
//                mActivity.getWindow().setAttributes(attrs);
//                mActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
//            } else {
//                attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
//                mActivity.getWindow().setAttributes(attrs);
//                mActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
//            }
//            toggleProcessDurationOrientation(fullScreen);
        }

    }

    /**
     * 设置界面方向带隐藏actionbar
     */
    private void tryFullScreen(boolean fullScreen) {
//        if (mActivity instanceof AppCompatActivity) {
//            ActionBar supportActionBar = ((AppCompatActivity) mActivity).getSupportActionBar();
//            if (supportActionBar != null) {
//                if (fullScreen) {
//                    supportActionBar.hide();
//                } else {
//                    supportActionBar.show();
//                }
//            }
//        }
        setFullScreen(fullScreen);
    }


    /**
     * 隐藏状态界面
     */
    private void hideStatusUI() {
//        iv_player.setVisibility(View.GONE);
//        query.id(ResourceUtils.getResourceIdByName(mContext, "id", "simple_player_settings_container")).gone();
//        query.id(ResourceUtils.getResourceIdByName(mContext, "id", "simple_player_select_stream_container")).gone();
//        query.id(ResourceUtils.getResourceIdByName(mContext, "id", "app_video_replay")).gone();
//        query.id(ResourceUtils.getResourceIdByName(mContext, "id", "app_video_netTie")).gone();
//        query.id(ResourceUtils.getResourceIdByName(mContext, "id", "app_video_loading")).gone();
        if (screenControll != null) {
            screenControll.onHidePanl(isPortrait, isLive, isPlaying());
        }
//        if (onControlPanelVisibilityChangeListener != null) {
//            onControlPanelVisibilityChangeListener.change(false);
//        }
    }

    /**
     * 隐藏所有界面
     */
    private void hideAll() {
        if (topControll != null) {
            topControll.onHidePanl(isPortrait, isLive, isPlaying());
        }
        if (bottomControll != null) {
            bottomControll.onHidePanl(isPortrait, isLive, isPlaying());
        }
        hideStatusUI();
    }

    public void setBrightness(int value) {
//        WindowManager.LayoutParams layout = this.mActivity.getWindow().getAttributes();
        if (brightness < 0) {
//            brightness = mActivity.getWindow().getAttributes().screenBrightness;
            if (brightness <= 0.00f) {
                brightness = 0.50f;
            } else if (brightness < 0.01f) {
                brightness = 0.01f;
            }
        }
        if (value < 1) {
            value = 1;
        }
        if (value > 100) {
            value = 100;
        }
//        layout.screenBrightness = 1.0F * (float) value / 100.0F;
//        if (layout.screenBrightness > 1.0f) {
//            layout.screenBrightness = 1.0f;
//        } else if (layout.screenBrightness < 0.01f) {
//            layout.screenBrightness = 0.01f;
//        }
//        this.mActivity.getWindow().setAttributes(layout);
    }


    /**
     * 显示或隐藏操作面板
     */
    public EmptyPlayerView operatorPanl() {
        isShowControlPanl = !isShowControlPanl;
        if (isShowControlPanl) {
            if (screenControll == null || screenControll.onShowPanl(isPortrait, isLive, isPlaying())) {
                if (topControll != null) {
                    topControll.onShowPanl(isPortrait, isLive, isPlaying());
                }
                if (bottomControll != null) {
                    bottomControll.onShowPanl(isPortrait, isLive, isPlaying());
                }
            }

        } else {
            if (screenControll != null) {
                screenControll.onHidePanl(isPortrait, isLive, isPlaying());
            }
            if (topControll != null) {
                topControll.onHidePanl(isPortrait, isLive, isPlaying());
            }
            if (bottomControll != null) {
                bottomControll.onHidePanl(isPortrait, isLive, isPlaying());
            }
        }
        return this;
    }

    /**
     * 快进或者快退滑动改变进度
     *
     * @param percent
     */
    private void onProgressSlide(float percent) {
        int position = videoView.getCurrentPosition();
        long duration = videoView.getDuration();
        long deltaMax = Math.min(100 * 1000, duration - position);
        long delta = (long) (deltaMax * percent);
        newPosition = delta + position;
        if (newPosition > duration) {
            newPosition = duration;
        } else if (newPosition <= 0) {
            newPosition = 0;
            delta = -position;
        }
        if (screenControll != null) {
            screenControll.onProgressSlide(delta, duration, newPosition);
        }
    }

    /**
     * 滑动改变声音大小
     *
     * @param percent
     */
    private void onVolumeSlide(float percent) {
        if (volume == -1) {
            volume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
            if (volume < 0)
                volume = 0;
        }
        int index = (int) (percent * mMaxVolume) + volume;
        if (index > mMaxVolume) {
            index = mMaxVolume;
        } else if (index < 0) {
            index = 0;
        }

        // 变更声音
        audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, index, 0);

        if (screenControll != null) {
            screenControll.onVolumeSlide((int) (index * 1.0 / mMaxVolume * 100));
        }
    }

    /**
     * 亮度滑动改变亮度
     *
     * @param percent
     */
    private void onBrightnessSlide(float percent) {
        if (brightness < 0) {
//            brightness = mActivity.getWindow().getAttributes().screenBrightness;
            if (brightness <= 0.00f) {
                brightness = 0.50f;
            } else if (brightness < 0.01f) {
                brightness = 0.01f;
            }
        }
//        WindowManager.LayoutParams lpa = mActivity.getWindow().getAttributes();
//        lpa.screenBrightness = brightness + percent;
//        if (lpa.screenBrightness > 1.0f) {
//            lpa.screenBrightness = 1.0f;
//        } else if (lpa.screenBrightness < 0.01f) {
//            lpa.screenBrightness = 0.01f;
//        }
//        if (screenControll != null) {
//            screenControll.onBrightnessSlide(lpa.screenBrightness);
//        }
//        mActivity.getWindow().setAttributes(lpa);
    }

    /**
     * @Override public void onBackPressed() {
     * if (player != null && player.onBackPressed()) {
     * return;
     * }
     * super.onBackPressed();
     * }
     */
    public boolean onBackPressed() {
        if (canChangeScreen() && getScreenOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
            Log.e(TAG, "qq will portrait by back pressed");
//            mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            return true;
        }
        return false;
    }

    private boolean canChangeScreen() {
        return bottomControll == null || bottomControll.canChangeScreen();
    }

    public boolean isPlaying() {
        return videoView != null && videoView.isPlaying();
    }

    public EmptyPlayerView setPortrait(boolean portrait) {
        isPortrait = portrait;
        return this;
    }

    public IGPlayerScreenControll getScreenControll() {
        return screenControll;
    }

    public void setScreenControll(IGPlayerScreenControll screenControll) {
        this.screenControll = screenControll;
    }

    public IGPlayerTopControll getTopControll() {
        return topControll;
    }

    public void setTopControll(IGPlayerTopControll topControll) {
        this.topControll = topControll;
    }

    public IGPlayerBottomControll getBottomControll() {
        return bottomControll;
    }

    public void setBottomControll(IGPlayerBottomControll bottomControll) {
        this.bottomControll = bottomControll;
    }

    public IGPlayerVoBrControll getVoBrControll() {
        return voBrControll;
    }

    public void setVoBrControll(IGPlayerVoBrControll voBrControll) {
        this.voBrControll = voBrControll;
    }

    public int getAutoConnectTime() {
        return autoConnectTime;
    }

    public void setAutoConnectTime(int autoConnectTime) {
        this.autoConnectTime = autoConnectTime;
    }

    public boolean isPlayerSupport() {
        return playerSupport;
    }

    public void setPlayerSupport(boolean playerSupport) {
        this.playerSupport = playerSupport;
    }

    public void setLive(boolean live) {
        isLive = live;
    }

    public boolean isErrorStop() {
        return isErrorStop;
    }

    public void setErrorStop(boolean errorStop) {
        isErrorStop = errorStop;
    }

    public boolean isAutoReConnect() {
        return isAutoReConnect;
    }

    public void setAutoReConnect(boolean autoReConnect) {
        isAutoReConnect = autoReConnect;
    }

    public boolean isAutoPlay() {
        return isAutoPlay;
    }

    public IMediaPlayer.OnInfoListener getOnInfoListener() {
        return onInfoListener;
    }

    public EmptyPlayerView setOnInfoListener(IMediaPlayer.OnInfoListener onInfoListener) {
        this.onInfoListener = onInfoListener;
        return this;
    }

    public OnStatusChanged getOnStatusChanged() {
        return onStatusChanged;
    }

    public EmptyPlayerView setOnStatusChanged(OnStatusChanged onStatusChanged) {
        this.onStatusChanged = onStatusChanged;
        return this;
    }

    public static int getMessageShowProgress() {
        return MESSAGE_SHOW_PROGRESS;
    }

//    public ViewGroup getBaseLay() {
//        return baseLay;
//    }

    public IjkVideoView getVideoView() {
        return videoView;
    }

//    public int getInitHeight() {
//        return initHeight;
//    }

    public String getCurrentUrl() {
        return currentUrl;
    }

    public IPlayClarity getCurrentCalarity() {
        return currentCalarity;
    }

    public List<IPlayClarity> getListVideos() {
        return listVideos;
    }

    public boolean isShowControlPanl() {
        return isShowControlPanl;
    }

    /**
     * 收起控制面板轮询，默认5秒无操作，收起控制面板，
     */
    private class AutoPlayRunnable implements Runnable {
        private int AUTO_PLAY_INTERVAL = 3000;
        private boolean mShouldAutoPlay;

        /**
         * 五秒无操作，收起控制面板
         */
        public AutoPlayRunnable() {
            mShouldAutoPlay = false;
        }

        public void start() {
            Log.e(TAG, "AutoPlayRunnable start mShouldAutoPlay " + mShouldAutoPlay);
            if (!mShouldAutoPlay) {
                mShouldAutoPlay = true;
                mHandler.removeCallbacks(this);
                mHandler.postDelayed(this, AUTO_PLAY_INTERVAL);
            }
        }

        public void stop() {
            Log.e(TAG, "AutoPlayRunnable stop mShouldAutoPlay " + mShouldAutoPlay);
            if (mShouldAutoPlay) {
                mHandler.removeCallbacks(this);
                mShouldAutoPlay = false;
            }
        }

        @Override
        public void run() {
            Log.e(TAG, "AutoPlayRunnable run mShouldAutoPlay " + mShouldAutoPlay
                    + "\n isForbidTouch " + isForbidTouch + " isShowControlPanl " + isShowControlPanl);
            if (mShouldAutoPlay) {
                mHandler.removeCallbacks(this);
                if (!isForbidTouch && isShowControlPanl) {
                    operatorPanl();
                }
            }
        }
    }

    /**
     * 播放器的手势监听
     */
    public class PlayerGestureListener extends GestureDetector.SimpleOnGestureListener {

        /**
         * 是否是按下的标识，默认为其他动作，true为按下标识，false为其他动作
         */
        private boolean isDownTouch;
        /**
         * 是否声音控制,默认为亮度控制，true为声音控制，false为亮度控制
         */
        private boolean isVolume;
        /**
         * 是否横向滑动，默认为纵向滑动，true为横向滑动，false为纵向滑动
         */
        private boolean isLandscape;

        /**
         * 双击
         */
        @Override
        public boolean onDoubleTap(MotionEvent e) {
            /**视频视窗双击事件*/
            if (!isForbidTouch && !isForbidDoulbeUp) {
//                toggleFullScreen();
                if (videoView.isPlaying()) {
                    videoView.pause();
                } else {
                    videoView.start();
                }
            }
            return true;
        }

        /**
         * 按下
         */
        @Override
        public boolean onDown(MotionEvent e) {
            isDownTouch = true;
            return super.onDown(e);
        }


        /**
         * 滑动
         */
        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
            Log.e(TAG, "PlayerGestureListener onScroll");
            if (!isForbidTouch) {
                float mOldX = e1.getX(), mOldY = e1.getY();
                float deltaY = mOldY - e2.getY();
                float deltaX = mOldX - e2.getX();
                if (isDownTouch) {
                    isLandscape = Math.abs(distanceX) >= Math.abs(distanceY);
//                    if (screenControll != null) {
//                        isVolume = screenControll.isVolumeArea(mOldX, screenWidthPixels);
//                    } else {
//                        isVolume = mOldX > screenWidthPixels * 0.5f;
//                    }
                    isDownTouch = false;
                }

                if (isLandscape) {
                    if (!isLive) {
                        /**进度设置*/
                        onProgressSlide(-deltaX / videoView.getWidth());
                    }
                } else {
                    float percent = deltaY / videoView.getHeight();
                    if (isVolume) {
                        /**声音设置*/
                        onVolumeSlide(percent);
                    } else {
                        /**亮度设置*/
                        onBrightnessSlide(percent);
                    }


                }
            }
            return super.onScroll(e1, e2, distanceX, distanceY);
        }

        /**
         * 单击
         */
        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            /**视频视窗单击事件*/
            if (!isForbidTouch) {
                operatorPanl();
            }
            return true;
        }
    }

}
